<?php

class Utils_JavaScript
{
	const JS_SRC = '<script type="text/javascript" src="%s"></script>';
	const JS_SCRIPT = '<script type="text/javascript">%s</script>';
	const JS_READY_FN = '$(document).ready(function() {%s})';
	
	private $view;
	private $urls;
	private $scripts;
	private $readyScripts;
	
	public function __construct(Zend_View_Interface $view) {
		$this->view = $view;
		$this->urls = array();
		$this->scripts = array();
		$this->readyScripts = array();
	}
	
	public function urls() {
		$urlsToString = '';
		if (count($this->urlScripts) > 0) {
			foreach ($this->urlScripts as $urlScript) {
				$urlsToString .= 
				$urlsToString .= '<script type="text/javascript" src="'.$this->view->reformatBaseUrl($urlScript).'"></script>';
			}
		}
		return (string) $urlsToString;
	}
	
	public function readyScripts() {
		sprintf(JS_SCRIPT, JS_READY_FN);
		
		$readyScriptsToString = '';
		if (count($this->readyScripts) > 0) {
			$javascript = '<script type="text/javascript">$(document).ready(function() {';
			foreach ($this->readyScripts as $readyScript) {
				$readyScriptsToString .= $readyScript;
			}
			$readyScriptsToString .= '})</script>';
		}
		return (string) $readyScriptsToString;
	}
	
	
}